<template>
	<view class="expense">
		<view class="expense-conten">
			<view class="repair-info">
				<view class="info-list" v-for="(item,index) in objDataList" :key="index">
					<view class="info-name">
						<text style="font-size: 30rpx;color: red;margin-right: 10rpx;" v-if="item.must">*</text>
						{{item.titele}}
					</view>
					<view class="info-conten">
						<input type="text" v-model="object[item.objName]" :maxlength="item.maxlength" :placeholder="item.placeholder">
					</view>
				</view>
			</view>
		</view>
		<view class="expense-submit">
			<view class="submit" @click="submit">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				object:{
					itemName:'',
					partsSupplier:'',
					partsName:'',
					specifications:'',
					materialsFee:'',
					workHoursFee:'',
					comment:''
				},
				objDataList:[{
					titele:'维修项目',
					objName:'itemName',
					placeholder:'请输入维修项目',
					must:true,
					maxlength:50
				},{
					titele:'配件供应商',
					objName:'partsSupplier',
					placeholder:'请输入配件供应商',
					maxlength:50
				},{
					titele:'配件名称',
					objName:'partsName',
					placeholder:'请输入配件名称',
					maxlength:50
				},{
					titele:'规格',
					objName:'specifications',
					placeholder:'请输入规格',
					maxlength:50
				},{
					titele:'材料费',
					objName:'materialsFee',
					placeholder:'请输入材料费',
					flag:true,
					maxlength:6
				},{
					titele:'工时费',
					objName:'workHoursFee',
					placeholder:'请输入工时费',
					flag:true,
					maxlength:6
				},{
					titele:'备注',
					objName:'comment',
					placeholder:'请输入备注',
					maxlength:100
				}],
				flag:true,
				index:0
			}
		},
		onLoad(options) {
			if(options.obj){
				let obj = JSON.parse(options.obj)
				this.object = obj.item,
				this.index = obj.index,
				this.flag = false,
				this.setNavTitle('编辑费用')
			}
		},
		onShow() {
			
		},
		methods:{
			isNumber(val){
				var regPos = /[^0-9.]/g; //判断是否是数字。
				if(regPos.test(val) ){
					return false;
				}else{
					return true;
				}
			},
			submit(){
				let _than = this
				if(!this.object.itemName){
					uni.showToast({
					  title: '维修项目不能为空！', // 标题
					  icon: 'error',  // 图标类型，默认success
					  duration: 1000  // 提示窗停留时间，默认1500ms
					})
					return false
				}
				if(this.isNumber(this.object.materialsFee) == false){
					uni.showToast({
					title: '材料费只能是数字！', // 标题
					  icon: 'error',  // 图标类型，默认success
					  duration: 1000  // 提示窗停留时间，默认1500ms
					})
					return false
				}
				if(this.isNumber(this.object.workHoursFee) == false){
					uni.showToast({
					title: '工时费只能是数字！', // 标题
					  icon: 'error',  // 图标类型，默认success
					  duration: 1000  // 提示窗停留时间，默认1500ms
					})
					return false
				}
				let formData = this.object
				if(this.flag == false){
					formData = {
						object: this.object,
						index: this.index,
						flag : false
					}
				}
				uni.setStorage({
					key: 'itemName',
					data:formData,
					success(res) {
						console.log('ad', formData)
						_than.jump()
					},
				})
			},
			setNavTitle(title){
				 uni.setNavigationBarTitle({
					title: title
				  })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.expense{
		width: 100%;
		min-height: 100vh;
		background-color: #f2f2f2;
		box-sizing: border-box;
		padding: 20rpx;
	}
	.expense-conten{
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
		border-radius: 20rpx;
	}
	.repair-info{
		width: 100%;
		padding: 20rpx 40rpx;
		background-color: #fff;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		.info-list{
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height:100rpx;
			font-size: 30rpx;
			position: relative;
			margin-bottom: 10rpx;
			.info-name{
				color: #aaaaaa
			}
			.info-conten{
				text-align: right;
			}
		}
	}
	.expense-submit{
		width: 100%;
		line-height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.submit{
		width: 90%;
		position: fixed;
		bottom: 50rpx;
		left: 50%;
		transform: translateX(-50%);
		border-radius: 20rpx;
		line-height: 50rpx;
		padding: 20rpx 0rpx;
		text-align: center;
		background-color: #dfb175;
	}
</style>